"use client";
import { GameListRep, GameRequest } from "@/api/home";
import { userInfoApi } from "@/api/login";
import { UserInfoRep, cleanBounsApi, getUserTransferApi } from "@/api/user";
import {
BalanceContent,
BonusContent,
FreeContent,
ReplayContent,
} from "@/components/ModalPopup/WalletDescribeModal";
import TipsModal, { ModalProps } from "@/components/TipsModal";
import Vip from "@/components/Vip";
import { HeaderImageMap } from "@/enums";
import useGame from "@/hooks/useGame";
import { Link, useRouter } from "@/i18n/routing";
import { usePollingStore } from "@/stores/usePollingStore";
import { useVipStore } from "@/stores/useVipStore";
import { useWalletStore } from "@/stores/useWalletStore";
import { WalletEnum } from "@/types";
import { vipImages } from "@/utils/constant";
import { copyText, percentage } from "@/utils/methods";
import { useRequest } from "ahooks";
import { Badge, Button, Mask, ProgressBar, Toast } from "antd-mobile";
import clsx from "clsx";
import { useTranslations } from "next-intl";
import Image from "next/image";
import { Fragment, useEffect, useMemo, useRef, useState } from "react";
import { shallow } from "zustand/shallow";
import ChangeAvatar from "./component/ChangeAvatar";
type Props = {
userInfo: UserInfoRep;
};
const VipCard = () => {
const t = useTranslations("ProfilePage");
// const vip_score_exp = useVipStore((state) => state.vipData!.vip_score_exp);
// const vip_level = useVipStore((state) => state.vipData!.vip_level);
// const vip_next_level = useVipStore((state) => state.vipData!.vip_next_level);
// const vip_exp = useVipStore((state) => state.vipData!.vip_exp);
const userVip = useVipStore((state) => {
return {
vip_score_exp: state.vipData!.vip_score_exp,
vip_level: state.vipData!.vip_level,
vip_next_level: state.vipData!.vip_next_level,
vip_exp: state.vipData!.vip_exp,
};
}, shallow);
const router = useRouter();
// Vip 图标
const vipIconElement = vipImages.map((item, index) => {
if (item.leve === userVip.vip_level) {
return (
{item.leve}
);
}
});
// const vipIconElement = vipImages.map((item, index) => {
// if (item.leve === userVip?.vip_level) {
// return (
//
//
//
// {item.leve}
//
//
// );
// }
// });
// if (!userVip) return null;
return (
{/*
{vipIconElement}
*/}
{/*
{userVip.vip_exp}xp
*/}
VIP{userVip?.vip_level}
{userVip.vip_exp}/{userVip.vip_score_exp}
VIP
{userVip.vip_next_level}
router.push("/vip")}>
CLUBE VIP
);
};
const WalletCard = () => {
const userMoney = useWalletStore((state) => {
return {
score: state.wallet.score,
point: state.wallet.point,
free_score: state.wallet.free_score,
free_transfer_min: state.wallet.free_transfer_min,
lose_transfer_min: state.wallet.lose_transfer_min,
is_point_transfer: state.wallet.is_point_transfer,
is_free_transfer: state.wallet.is_free_transfer,
is_lose_transfer: state.wallet.is_lose_transfer,
lose_score: state.wallet.lose_score,
};
}, shallow);
const t = useTranslations("ProfilePage");
const tcdoe = useTranslations();
const tipsRef = useRef(null);
const [tipsStatus, setTipsStatus] = useState("Bonus");
const modalHandler = (key: keyof typeof WalletEnum) => {
setTipsStatus(key);
tipsRef.current?.onOpen();
};
// 未完成游戏
const gameModelRef = useRef(null);
const game = useRef<(GameListRep & { mode: GameRequest["mode"] }) | null>(null);
// 彩金、免费币、重玩币提现到钱包操作
const handleAcquire = async (wallet_type: number, transfer: boolean) => {
if (!transfer) return;
// 先判断是否有未完成的游戏
const { data }: any = await userInfoApi();
// 如果有未完成游戏 彩金游戏-2、免费游戏-3、重玩游戏-4
if (wallet_type === 2 && data.play_list && data.play_list.length > 0) {
game.current = data.play_list[0];
game.current!.mode = 1;
gameModelRef.current?.onOpen();
return;
}
if (wallet_type === 3 && data.free_game_list && data.free_game_list.length > 0) {
game.current = data.free_game_list[0];
gameModelRef.current?.onOpen();
game.current!.mode = 2;
return;
}
if (wallet_type === 4 && data.lose_game_list && data.lose_game_list.length > 0) {
game.current = data.lose_game_list[0];
game.current!.mode = 3;
gameModelRef.current?.onOpen();
return;
}
getUserTransferApi({ wallet_type })
.then((res) => {
if (res.code === 200) {
Toast.show(tcdoe("code.200"));
setTimeout(() => {
tipsRef.current?.onClose();
}, 1000);
}
})
.catch((error) => {
Toast.show(tcdoe(`code.${error.data.code}`));
});
};
const { getGameUrl } = useGame();
const goGame = () => {
const current = game.current;
getGameUrl(current!, { id: current?.id + "", mode: game.current?.mode! });
tipsRef.current?.onClose();
gameModelRef.current?.onClose();
};
const walletCfg = useMemo(() => {
return [
{
title: t("balance"),
icon: "icon-qianbao3",
onClick: () => modalHandler(WalletEnum.Balance),
value: userMoney.score || "0.0",
key: "balance",
dot: userMoney.is_point_transfer ? Badge.dot : null,
},
{
title: t("bonus"),
icon: "icon-meiyuanzhanghuyue",
onClick: () => modalHandler(WalletEnum.Bonus),
value: userMoney.point || "0.0",
key: "bonus",
dot: userMoney.is_point_transfer ? Badge.dot : null,
},
{
title: t("free"),
icon: "icon-Free-Tag",
onClick: () => modalHandler(WalletEnum.Free),
value: userMoney.free_score || "0.0",
key: "free",
iconStyle: { fontSize: ".22rem" },
dot:
userMoney.is_free_transfer &&
userMoney.free_score >= (userMoney?.free_transfer_min || 0)
? Badge.dot
: null,
},
{
title: t("replay"),
icon: "icon-meiyuan2",
onClick: () => modalHandler(WalletEnum.Replay),
value: userMoney.lose_score || "0.0",
key: "replay",
dot:
userMoney.is_lose_transfer &&
userMoney.lose_score >= (userMoney?.lose_transfer_min || 0)
? Badge.dot
: null,
},
];
}, [userMoney]);
return (
<>
{t("modalTitle")}
}
>
{/*/!*现金*!/*/}
{tipsStatus === WalletEnum.Balance ? : null}
{/*/!* 彩金*!/*/}
{tipsStatus === WalletEnum.Bonus ? (
) : null}
{/*/!* 免费币 *!/*/}
{tipsStatus === WalletEnum.Free ? (
) : null}
{/*/!* 重玩币 *!/*/}
{tipsStatus === WalletEnum.Replay ? (
) : null}
{/* 提现拦截 */}
Existem jogos de bônus pendentes que não podem iniciar a retirada.
{walletCfg.map((item, index) => {
return (
);
})}
>
);
};
const NoBounsWarn = ({ visible, onClose, onConfirm }: any) => {
const doClose = () => {
if (typeof onClose === "function") onClose();
};
const doConfirm = () => {
if (typeof onConfirm === "function") onConfirm();
};
return (
A demanda atual de fluxo de retirada de bônus é excessiva,Se esvaziar o
bônus e retirar a demanda de água corrente?
);
};
export const ProfileHeader = () => {
const t = useTranslations("ProfilePage");
const userMoney = useWalletStore((state) => {
return {
target_point_rollover: state.wallet?.target_point_rollover,
score: state.wallet?.score,
point: state.wallet?.point,
no_bonus_config: state.wallet?.no_bonus_config,
current_score_rollover: state.wallet?.current_score_rollover,
target_score_rollover: state.wallet?.target_score_rollover,
};
}, shallow);
const refresh = usePollingStore((state) => state.refresh);
const tc = useTranslations();
const vipInfo = useVipStore((state) => state.vipData);
// const { wallet, setWallet } = useWalletStore((state) => ({
// wallet: state.wallet,
// setWallet: state.setWallet,
// }));
const router = useRouter();
const [isShowNoBounsWarn, setIsShowNoBounsWarn] = useState(false);
const [isShowAvatar, setIsShowAvatar] = useState(false);
const [isShowed, setIsShowed] = useState(false);
const { data: userInfo, run: refreshUserInfo } = useRequest(userInfoApi, {
pollingErrorRetryCount: 1,
});
// const userInfo = useMemo(() => {
// return data?.data;
// }, [data]);
useEffect(() => {
const curMul =
userMoney.target_point_rollover / ((userMoney.score || 0) + (userMoney.point || 0));
const percent = percentage(
userMoney.current_score_rollover,
userMoney.target_score_rollover
);
const config = userMoney.no_bonus_config;
if (curMul >= (config || 0) && !isShowed && percent < 100) {
setTimeout(() => {
setIsShowNoBounsWarn(true);
}, 1000);
setIsShowed(true);
}
//todo 修改数据回显
}, [isShowed]);
const handler = () => {
if (!!userMoney.score) {
router.push("/deposit?target=2");
} else {
Toast.show("no money");
}
};
const doConfirm = async () => {
Toast.show({
icon: "loading",
maskClickable: false,
});
setIsShowNoBounsWarn(false);
const res = await cleanBounsApi(1);
if (res?.code && [6001, 6002].includes(res?.data?.code)) {
const str = t(`bouns${res?.data?.code}`);
Toast.show({
content: str,
icon: "fail",
});
}
Toast.show({
content: t("success"),
icon: "success",
});
// const walletRes = await getUserMoneyApi();
// setWallet(walletRes?.data);
refresh && refresh();
};
const doCopyUsreId = (evt: any) => {
(evt as any).stopPropagation();
copyText(`${userInfo.data.user_phone}`);
Toast.show({ icon: "success", content: tc("SummaryPage.copySuc"), maskClickable: false });
};
return (
<>
setIsShowAvatar(true)}>
{userInfo?.data?.nick_name || t("Conta")}
{userInfo?.data?.user_phone || ""}
{/*
*/}
{/*vipcard*/}
{t("Depósito")}
{t("Sacar")}
setIsShowNoBounsWarn(false)}
onConfirm={doConfirm}
>
{
if (needRefresh) refreshUserInfo();
setIsShowAvatar(false);
}}
>
>
);
};